package priv.stones.io.Scanner.file;

import java.io.*;

/**
 * @Author: Stones
 * @Description:
 * @Date: 2017/11/1 15:09
 */
class  Persion implements Serializable{
    private transient String name;
    private int age;

    public Persion(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Persion{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class serialize1 {

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Persion persion = new Persion("胡金阳11", 25);
        ser(persion);

        Persion persion1 = dser();
        System.out.println(persion1);

    }

    static void ser(Object obj) throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("e:\\persion.ser")));
        oos.writeObject(obj);
        oos.close();
    }

    static Persion dser() throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("e:\\persion.ser")));
        Persion persion = (Persion) ois.readObject();
        ois.close();

        return persion;
    }


}
